import 'package:flutterstudyapplast/business/models/article_collect_item.dart';
import 'package:flutterstudyapplast/business/models/article_item.dart';
import 'package:flutterstudyapplast/business/models/banner_item.dart';

class HttpHelper{
  static Map<String,dynamic> createArticleList(data){
    var map = data["data"];
    var datas = map["datas"];
    Map<String,dynamic> result = Map<String,dynamic>();
    result["total"] = map["total"];
    List<ArticleItem> items = [];
    for(var item in datas){
      items.add(ArticleItem(id: item["id"],author: item["author"],niceDate: item["niceDate"],
      title: item["title"],chapterName: item["chapterName"],isCollect: item["collect"],url: item["link"]));
    }
    result["datas"] = items;
    return result;
  }
  static List<BannerItem> createBannerList(data){
    var datas = data["data"];
    List<BannerItem> banners = [];
    for(var item in datas){
      banners.add(BannerItem(url: item["url"],imagePath: item["imagePath"]));
    }
    return banners;
  }
  static Map<String,dynamic> createArticleCollects(data){
    var map = data['data'];
    var datas = map["datas"];
    Map<String,dynamic> result = Map<String,dynamic>();
    result["total"] = map["pageCount"];
    List<ArticleCollctItem> items = [];
    for(var item in datas){
      print(item);
      items.add(ArticleCollctItem(id: item["originId"]??item["id"],author: item["author"],niceDate: item["niceDate"],
      title: item["title"],chapterName: item["chapterName"],isCollect: true,url: item["link"]));
    }
    result["datas"] = items;
    return result;
  }
  static List<ArticleCollctItem> createArticleWebsiteLista(data){
    var datas = data["data"];
    List<ArticleCollctItem> items = [];
    for(var item in datas){
      items.add(ArticleCollctItem(title: item["name"],url: item["link"],id: item["id"]));
    }
    return items;
  }
}